package com.hyxt.DTO;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hyxt.api.TermianalLinkServer;
import com.hyxt.utils.RedisPoolUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author shenp
 * @version v1.0
 * @Description redis启动监听
 * @Date: Create in 11:05 2017/11/27
 * @Modifide By:
 **/
@Component
public class RedisListenerApplication {
    @Autowired
    TermianalManagerListener termianalManagerListener;
    @Autowired
    TermianalReMessageListener termianalReMessageListener;
    @Autowired
    T809ManagerListener t809ManagerListener;
    @Autowired
    T809ReMessageListener t809ReMessageListener;

    public void startListener() {
        //日志
        Log log = LogFactory.getLog(RedisListenerApplication.class);
        //监听处理类
        ExecutorService pool =  new ThreadPoolExecutor(5,20,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
        System.out.println("启动监听。。。");
        pool.submit(new Runnable() {
            @Override
            public void run() {
                RedisPoolUtil.getJedis().subscribe(termianalManagerListener,"termianalManager");
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                RedisPoolUtil.getJedis().subscribe(termianalReMessageListener,"termianalReMessage");
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                RedisPoolUtil.getJedis().subscribe(t809ManagerListener,"t809Manager");
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                RedisPoolUtil.getJedis().subscribe(t809ReMessageListener,"t809ReMessage");
            }
        });

    }
}
